import * as echarts from 'echarts/core'

import dayjs from 'dayjs'

let yMax = 400

export const lineOptions = {
  tooltip: {
    trigger: 'axis',
    axisPointer: { // 坐标轴指示器，坐标轴触发有效
      type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
    }
  },
  grid: {
    left: '2%',
    right: '4%',
    bottom: '14%',
    top: '16%',
    // show: true,
    // borderWidth: 20,
    containLabel: true
  },

  legend: {
    show: false,
  },

  xAxis: {
    type: 'category',
    // data: ['12.8', '12.9', '12.10', '12.11', '12.12', '12.13', '12.14'],
    data: [],
    axisLine: {
      lineStyle: {
        color: 'rgba(90,92,107,0.5)'

      }
    },
    axisLabel: {
      // interval: 0,
      // rotate: 40,
      color: "#fff",
      fontFamily: 'Microsoft YaHei'
    },
  },

  yAxis: {
    type: 'value',
    axisLine: {
      // 隐藏 y轴左边线
      show: false,
      lineStyle: {
        color: 'white'
      }
    },
    // 假设最大是400， 在下面的 series 里面每个类型多加一个数据，专门做背景，值就是都填这里max的值
    max: yMax,

    splitLine: {
      show: true,
      lineStyle: {
        color: '#5a5c6b33'
      }
    },
    axisLabel: {}
  },

  series: [
    {
      name: '访客',
      type: 'bar',
      barWidth: '15%',
      label: {
        color: '#fff',
        show: true,
        position: 'top'
      },
      // 显示灰色背景
      showBackground: true,
      backgroundStyle: {
        // borderWidth: 10,
        color: 'rgba(255,255,255,0.04)',
        // borderColor: 'rgba(255,255,255,0.04)'
        // color: 'red',
        // borderColor: 'red'
      },


      itemStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: 'rgba(0,175,253,0.8)'
        }, {
          offset: 1,
          color: 'rgba(0,175,253,0)'
        }]),

        borderRadius: [10, 10, 0, 0],
      },

      // data: [100, 80, 25, 70, 95, 55, 12, 34],
      data: [],

      zIndex: 10
    },

    {
      name: '员工',
      type: 'bar',
      barWidth: '15%',
      barGap: '100%',
      // 显示灰色背景
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(255,255,255,0.04)',
      },

      label: {
        color: '#fff',
        show: true,
        position: 'top'
      },
      itemStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: 'rgba(255,147,0,0.8)'
        }, {
          offset: 1,
          color: 'rgba(255,147,0,0)'
        }]),
        borderRadius: [10, 10, 0, 0]

      },
      // data: [11, 22, 33, 55, 77, 87, 45, 12]
      data: [],
    }
  ]
}

export const getDateList = () => {
  let dateList = []

  let today = dayjs().format('YYYY-MM-DD')

  dateList.push(today)

  for (let i = 0; i < 30; i++) {
    let prev = dayjs().subtract(i + 1, 'day').format('YYYY-MM-DD')

    dateList.unshift(prev)
  }

  return dateList
}

export const getRandomList = () => {
  let dateList = getDateList()

  /**
   * 取1-30  中间的7天
   *
   * 假设随机数是 1-起点， 取1-7
   * 如果是 24 ， 24-30
   * 如果是25 不行
   */

  const startDate = 1 + parseInt(Math.random() * 24)

  let xData = dateList.splice(startDate, 7)

  let d1 = new Array(7).fill('').map(() => {
    return parseInt(Math.random() * 400)
  })

  let d2 = new Array(7).fill('').map(() => {
    return parseInt(Math.random() * 400)
  })


  return {
    xData,
    yData: [
      d1,
      d2
    ]
  }
}
